using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;

namespace Cartoon
{
    partial class ControlContainer : UserControl 
    {
        int m_ControlYCoordinate = 0;

        public ControlContainer()
        {
            InitializeComponent();
        }       

        public void Add(Control control)
        {
            if (control == null)
                throw new ArgumentNullException("control");

            SetControl(control);
            this.SuspendLayout();
            this.Controls.Add(control);
            this.ResumeLayout(false);
            this.PerformLayout();
        }

        public void AddRange(Control[] controls)
        {
            if (controls == null)
                throw new ArgumentNullException("controls");

            foreach (Control control in controls)
                SetControl(control);                      

            this.SuspendLayout();
            this.Controls.AddRange(controls);
            this.ResumeLayout(false);
            this.PerformLayout();
        }

        public void Clear()
        {
            this.Controls.Clear();
            m_ControlYCoordinate = 0;
        }

        void SetControl(Control control)
        {
            Size a = control.Size;
            control.Location = new Point(0, m_ControlYCoordinate);
            control.Anchor = (AnchorStyles)((AnchorStyles.Top | AnchorStyles.Right | AnchorStyles.Left));
            a = control.Size;

            m_ControlYCoordinate += control.Height;
        }
    }
}
